package com.mva.User_DAO;

import com.mva.common.DataDictionaryConstants;
import com.mva.common.Displayable;
import com.mva.common.StringUtils;
import com.mva.common.Validator;

/*******************************************************************************
 The <big><b>User</b></big> class implements the <b>Displayable</b> &
 <b>Cloneable</b> interfaces to create a <b>User</b> object

 @author D.Merkling - 1:33:38 PM - Aug 22, 2011

 @version 1.2  
 *******************************************************************************/
public class User implements Displayable, Cloneable, DataDictionaryConstants
  {
   private String User;
   private String Nm_Pfx;
   private String Nm_Fst;
   private String Nm_Mid;
   private String Nm_Lst;
   private String Nm_Sfx;
   private int    Addr;
   private String Phn1;
   private String Phn2;
   private String Email;
   private String Email2;

   /*******************************************************************************
	This constructor creates a new <b>User</b> object with default values
   *******************************************************************************/
   public User ()
	 {
	  this.User   = " ";
	  this.Nm_Pfx = " ";
	  this.Nm_Fst = " ";
	  this.Nm_Mid = " ";
	  this.Nm_Lst = " ";
	  this.Nm_Sfx = " ";
	  this.Addr   = 0;
	  this.Phn1   = " ";
	  this.Phn2   = " ";
	  this.Email  = " ";
	  this.Email2 = " ";
	 }

   /*******************************************************************************
	This constructor creates a new <b>User</b> object with attribute values as
	defined by the provided parameters
	@param User A <b><i>String</i></b> variable
	@param Name - prefix A <b><i>String</i></b> variable
	@param Name - first A <b><i>String</i></b> variable
	@param Name - middle A <b><i>String</i></b> variable
	@param Name - last A <b><i>String</i></b> variable
	@param Name - suffix A <b><i>String</i></b> variable
	@param Addr An <b><i>int</i></b> variable
	@param Phone #1 A <b><i>String</i></b> variable
	@param Phone #2 A <b><i>String</i></b> variable
	@param Email #1 A <b><i>String</i></b> variable
	@param Email #2 A <b><i>String</i></b> variable
   *******************************************************************************/
   public User (String User, String Nm_Pfx, String Nm_Fst, String Nm_Mid, String Nm_Lst, String Nm_Sfx, int Addr, String Phn1, String Phn2, String Email, String Email2)
	 {
	  this.User   = User;
	  this.Nm_Pfx = Nm_Pfx;
	  this.Nm_Fst = Nm_Fst;
	  this.Nm_Mid = Nm_Mid;
	  this.Nm_Lst = Nm_Lst;
	  this.Nm_Sfx = Nm_Sfx;
	  this.Addr   = Addr;
	  this.Phn1   = Phn1;
	  this.Phn2   = Phn2;
	  this.Email  = Email;
	  this.Email2 = Email2;
	 }

   /*******************************************************************************
	Clones a current <b>User</b> object to create a new one
	@return User - A <b>User</b> object
	@throws CloneNotSupportedException 
   *******************************************************************************/
   public Object clone () throws CloneNotSupportedException
	 {
	  return super.clone();
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>User</b> attribute for the current <b>User</b>
	object
	<br><br>
	The value must be uppercase, trimmed, & left-justified
	<br><br>
	@param User A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setUser (String usr)
	 {
	  String tmpUsr = usr.toUpperCase();
	  tmpUsr        = tmpUsr.trim();
	  this.User     = tmpUsr;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>User</b> attribute from the current
	<b>User</b> object
	<br><br>
	@return User - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getUser ()
	 {
	  return User;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>name prefix</b> attribute for the current
	<b>User</b> object
	
	The value must be trimmed & left-justified
	
	@param Name - prefix A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setNmPfx (String nmPfx)
     {
	  String tmpNm = nmPfx.trim();
	  this.Nm_Pfx  = tmpNm;
	 }

   /*******************************************************************************
 	Retrieves the <b><i>String</i></b> <b>prefix name</b> attribute from the
 	current <b>User</b> object
	@return Name - prefix - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getNmPfx ()
	 {
	  return Nm_Pfx;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>first name</b> attribute for the current
	<b>User</b> object
	
	The value must be trimmed & left-justified
	
	@param Name - first A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setNmFst (String nmFst)
	 {
	  String tmpNm = nmFst.trim();
	  this.Nm_Fst  = tmpNm;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>first name</b> attribute from the current
	<b>User</b> object
	@return Name - first - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getNmFst ()
	 {
	  return Nm_Fst;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>middle name</b> attribute for the current
	<b>User</b> object
	
	The value must be trimmed & left-justified
	
	@param Name - middle A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setNmMid (String nmMid)
	 {
	  String tmpNm = nmMid.trim();
	  this.Nm_Mid  = tmpNm;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>middle name</b> attribute from the current
	<b>User</b> object
	@return Name - middle - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getNmMid ()
	 {
	  return Nm_Mid;
	 }
   
   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>last name</b> attribute for the current
	<b>User</b> object
	
	The value must be trimmed & left-justified
	
	@param Name - last A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setNmLst (String nmLst)
	 {
	  String tmpNm = nmLst.trim();
	  this.Nm_Lst  = tmpNm;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>last name</b> attribute from the current
	<b>User</b> object
	@return Name - last - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getNmLst ()
	 {
	  return Nm_Lst;
	 }
   
   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>name suffix</b> attribute for the current
	<b>User</b> object
	
	The value must be trimmed & left-justified
	
	@param Name - suffix A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setNmSfx (String nmSfx)
	 {
	  String tmpNm = nmSfx.trim();
	  this.Nm_Sfx  = tmpNm;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>name suffix</b> attribute from the current
	<b>User</b> object
	@return Name - suffix - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getNmSfx ()
	 {
	  return Nm_Sfx;
	 }

   /*******************************************************************************
	Sets the <b><i>int</i></b> <b>Addr</b> attribute for the current
	<b>User</b> object
	<br><br>
	The value must be an unsigned, positive integer
	table
	<br><br>
	@param Addr An <b><i>int</i></b> variable
	@return Success/failure - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setAddr (int addr)
	 {
	  boolean isValid = Validator.isAddressValid(addr);
	  if (isValid)
	    {
		 this.Addr = addr;
		 return true;  
	    }
	  else
	    {
		 this.Addr = 0;
		 return false; 
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>int</i></b> <b>Addr</b> attribute from the current
	<b>User</b> object
	@return Addr - An <b><i>int</i></b> variable
   *******************************************************************************/
   public int getAddr ()
	 {
	  return Addr;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>phone #1</b> attribute for the current
	<b>User</b> object
	<br><br>
	The value must be trimmed, left-justified, & formatted as a proper phone
	number - 999-999-9999
	
	@param Phone #1 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setPhn1 (String inPhn)
	 {
	  String phn1   = inPhn.trim();
	  String phn2   = "";
      phn2 = Validator.validatePhone(phn1);
	  if (phn2.equals("**BAD**"))
	    {
		 System.out.println("Phone #1 not valid; saved as blanks");
		 return false;
	    }
	  else
	    {
		 this.Phn1 = phn2;
		 return true;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>phone #1</b> attribute from the current
	<b>User</b> object
	@return Phone #1 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getPhn1 ()
	 {
	  return Phn1;
	 }
  
   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>phone #2</b> attribute for the current
	<b>User</b> object
	
	The value must be trimmed, left-justified, & formatted as a proper phone
	number - 999-999-9999
	
	@param Phone #2 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setPhn2 (String inPhn)
	 {
	  String phn1   = inPhn.trim();
	  String phn2   = "";
      phn2 = Validator.validatePhone(phn1);
	  if (phn2.equals("**BAD**"))
	    {
		 System.out.println("Phone #2 not valid; saved as blanks");
		 return false;
	    }
	  else
	    {
		 this.Phn2 = phn2;
		 return true;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>phone #2</b> attribute from the current
	<b>User</b> object
	@return Phone #2 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getPhn2 ()
	 {
	  return Phn2;
	 }
   
   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>email #1</b> attribute for the current
	<b>User</b> object
	
	The value must be trimmed, left-justified, & formatted as a proper email
	address - xxxxxxxx@yyyyyyyy.zzz
	
	@param Email #1 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setEmail (String inEml)
	 {
	  String  eml1    = inEml.trim();
	  boolean isValid = false;
	  isValid         = Validator.validateEmail(eml1);
	  if (isValid)
	    {
		 this.Email = eml1;
		 return true;
	    }
	  else
	    {
		 System.out.println("Email #1 not valid format; saved as blanks");
		 return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>email #1</b> attribute from the current
	<b>User</b> object
	@return Email #1 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getEmail ()
	 {
	  return Email;
	 }
   
   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>email #2</b> attribute for the current
	<b>User</b> object
	
	The value must be trimmed, left-justified, & formatted as a proper email
	address - xxxxxxxx@yyyyyyyy.zzz
	
	@param Email #2 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setEmail2 (String inEml)
	 {
	  String  eml1    = inEml.trim();
	  boolean isValid = false;
	  isValid         = Validator.validateEmail(eml1);
	  if (isValid)
	    {
		 this.Email2 = eml1;
		 return true;
	    }
	  else
	    {
		 System.out.println("Email #2 not valid format; saved as blanks");
		 return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>email #2</b> attribute from the current
	<b>User</b> object
	@return Email #2 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getEmail2 ()
	 {
	  return Email2;
	 }
   
   /*******************************************************************************
	Determines whether or not all of the attribute values of one <b>User</b>
	object are equal to all of the attribute values of a second <b>User</b>
	object
	@param object A	<b>User</b> object
	@return true/false - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean equals(Object object)
     {
      if (object instanceof User)
        {
         User user2 = (User) object;
         if (User.equals(user2.getUser())     &&
             Nm_Pfx.equals(user2.getNmPfx())  &&
             Nm_Fst.equals(user2.getNmFst())  &&
             Nm_Mid.equals(user2.getNmMid())  &&
             Nm_Lst.equals(user2.getNmLst())  &&
             Nm_Sfx.equals(user2.getNmSfx())  &&
             Addr == user2.getAddr()          &&
             Phn1.equals(user2.getPhn1())     &&
             Phn2.equals(user2.getPhn2())     &&
             Email.equals(user2.getEmail())   &&
             Email2.equals(user2.getEmail2()))
         return true;
        }
      return false;
     }

   /*******************************************************************************
	Retrieves a one-line formatted list of the attribute values of the current
	<b>User</b> object for use in a table display
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String toTableString ()
	 {
	  return StringUtils.padWithSpaces(this.User,   User_LEN)  + " | " +
	         StringUtils.padWithSpaces(this.Nm_Pfx, Nm_LEN)    + " | " +
	         StringUtils.padWithSpaces(this.Nm_Fst, Nm_LEN)    + " | " +
	         StringUtils.padWithSpaces(this.Nm_Mid, Nm_LEN)    + " | " +
	         StringUtils.padWithSpaces(this.Nm_Lst, Nm_LEN)    + " | " +
	         StringUtils.padWithSpaces(this.Nm_Sfx, Nm_LEN)    + " | " +
	         this.Addr                                         + " | " +
	         StringUtils.padWithSpaces(this.Phn1,   Phn_LEN)   + " | " +
	         StringUtils.padWithSpaces(this.Phn2,   Phn_LEN)   + " | " +
	         StringUtils.padWithSpaces(this.Email,  Email_LEN) + " | " +
	         StringUtils.padWithSpaces(this.Email2, Email_LEN);
	 }
   
   /*******************************************************************************
	Retrieves a formatted list of the attribute values of the current
	<b>User</b> object
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String toString()
	 {
	  return "User       : " + this.User        + "\n" +
	         "Name prefix: " + this.Nm_Pfx      + "\n" +
		     "First name : " + this.Nm_Fst      + "\n" +
		     "Middle name: " + this.Nm_Mid      + "\n" +
		     "Last name  : " + this.Nm_Lst      + "\n" +
		     "Name suffix: " + this.Nm_Sfx      + "\n" +
		     "Address ID : " + this.Addr        + "\n" +
		     "Phone #1   : " + this.getPhn1()   + "\n" +
		     "Phone #2   : " + this.getPhn2()   + "\n" +
	         "Email #1   : " + this.getEmail()  + "\n" +
             "Email #2   : " + this.getEmail2() + "\n";
	 }
   
   /*******************************************************************************
	Retrieves a formatted displayable list of the attribute values of the current
	<b>User</b> object
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getDisplayText()
    {
	  return toString();
    }
  }